package com.sxj.corejava.code09_集合;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author 石小俊
 * @date 2024年05月09日 19:33
 */
public class Test01_集合工具类 {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(3);
        list.add(8);
        list.add(5);
        System.out.println(list);
        Collections.addAll(list, 10, 2, 4, 6);
        System.out.println(list);
        System.out.println("最大值:" + Collections.max(list));
        System.out.println("最小值:" + Collections.min(list));

        // 升序
        Collections.sort(list);
        System.out.println("升序排序后:" + list);

        // 降序
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if (o1 > o2) {
                    return -1;
                } else if (o1 < o2) {
                    return 1;
                }
                return 0;
            }
        });
        System.out.println("降序排序后:" + list);
        Collections.reverse(list);
        System.out.println("反转后:" + list);
        Collections.swap(list, 1, 6);
        System.out.println(list);
        Collections.fill(list, 1);
        System.out.println(list);
    }

}
